﻿using System.Collections.Generic;
using System.Resources;
using System.Collections;

namespace EasyLib.Configuration
{
    /// <summary>
    /// class extends from AbstractConfig, which will load data from resx file
    /// </summary>
    public class ResxConfig : FileConfig
    {
        internal protected ResxConfig(string configResource) : base(configResource) { }

        /// <summary>
        /// override method, read from resx file to retrieve config items and store in a collection
        /// </summary>
        public override void LoadData()
        {
            IDictionary<string, string> items = new Dictionary<string, string>();
            
            using (ResXResourceReader reader = new ResXResourceReader(ConfigFilePath))
            {
                foreach (DictionaryEntry property in reader)
                {
                    string key = property.Key as string;
                    string value = property.Value as string;

                    items[key] = value;
                }
                reader.Close();
            }

            if (items.Count != 0)
            {
                ConfigUtils.Cache[ConfigUtils.GetCategoryIfResxOrPropsFile(ConfigResource)] = items;
            }
        }
    }
}